#include <string.h>
#include <iostream>

using namespace std;

class String{
public:
    //无参构造
    String()
        :_pstr(new char [1]())
    {
        cout << "String()" << endl;
    }
    //有参构造
    String(const char *pstr)
        :_pstr(new char [strlen(pstr)+1]())
    {
        strcpy(_pstr,pstr);
        cout << "String(cnost char *)" << endl;
    }
    //拷贝构造函数
    String(const String & rhs)
        :_pstr(new char [strlen(rhs._pstr)+1]())
    {
        strcpy(_pstr,rhs._pstr);
        cout << "String(const String & rhs)" << endl;
    }
    //移动构造函数
    String(String && rhs)
        :_pstr(rhs._pstr)
    {
        cout << "String(String && rhs)" << endl;
        rhs._pstr = nullptr;
    }
    //赋值运算符函数
    String &operator=(const String &rhs)
    {
        cout << "String &operator(cnost String &rhs)" << endl;
        if(this != &rhs){
            delete [] _pstr;
            _pstr = new char [strlen(rhs._pstr)+1]();
            strcpy(_pstr,rhs._pstr);
        }
        return *this;
    }
    //移动赋值运算符函数
    String &operator=(String &&rhs)
    {
        cout << "String &operator(String && rhs)" << endl;
        if(this != &rhs){
            delete [] _pstr;
            _pstr = rhs._pstr;
            rhs._pstr = nullptr;
        }
        return *this;
    }
    //析构函数
    ~String(){
        cout << "~String()" << endl;
        if(_pstr){
            delete [] _pstr;
            _pstr = nullptr;
        }
    }

    char * stringpstr(){
        return _pstr;
    }


private:
    char * _pstr;
};


void test(){
    //String s1 = String("xww");
    //String s2 = String("666");
    //s2 = move(s1);
    //s1 = String("hello");
    int (&&a) = 100;
    cout << a << endl;
    cout << &a << endl;
}


int main()
{
    test();
    return 0;
}

